package kr.co.choongang;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/EmpSelect")
public class EmpSelectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public EmpSelectServlet() throws ClassNotFoundException {

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=euc-kr");
		PrintWriter out = response.getWriter();
		out.print("<html><body>");
		EmpSelectDTO empSelectDTO = null;
		try {
			EmpSelectDAO empSelectDAO = new EmpSelectDAO();
			empSelectDAO.setConnection();
			empSelectDAO.setStatement(null);
			ResultSet rs = empSelectDAO.executeQuerySelect();
			while (rs.next()) {
				empSelectDTO = empSelectDAO.setSelectResult();
				out.print(empSelectDTO.getEmp_id() + "\t"
						+ empSelectDTO.getEname() + "\t"
						+ empSelectDTO.getSalary() + "\t"
						+ empSelectDTO.getDepart() + "<br>");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

		out.print("</body></html>");
	}

}
